package com.swas.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.swas.service.PatrolCheckService;
import com.swas.entity.PatrolCheck;
import com.swas.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.swas.vo.CheckTableVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/patrolcheck")
public class PatrolCheckController {

    @Autowired
    private PatrolCheckService patrolCheckService;
    @GetMapping("/findAll")
    public ResultVO findAll(@RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "5") Integer pageSize,
                            String taskno,
                            String taskname,
                            String tasktype,
                            Integer taskstatu){
        PageHelper.startPage(pageNum,pageSize);
        List<CheckTableVO> list = patrolCheckService.findAll(pageNum, pageSize,taskno,taskname,tasktype,taskstatu);
        PageInfo<CheckTableVO> pageInfo = new PageInfo<>(list);
        return ResultVO.success("查询成功",pageInfo);
    }
    @PutMapping("/updateCheck")
    public ResultVO updateCheck(@RequestBody CheckTableVO checkTableVO) {
        boolean b = patrolCheckService.updateCheck(checkTableVO);
        if (b) {
            return ResultVO.success("修改成功");
        }
        return ResultVO.fail("修改失败");
    }

    @GetMapping("/taskId/{taskid}")
    public ResultVO getByTaskId(@PathVariable("taskid") Integer taskid) {
        PatrolCheck patrolCheck = patrolCheckService.getByTaskId(taskid);
        return ResultVO.success(patrolCheck);
    }
}
